<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>约健</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {include file="public:headfile"}
</head>



<body class="hold-transition sidebar-mini">
<div class="wrapper">

    {include file="public:head"}

    {include file="public:slidemenu"}

    <div class="content-wrapper">

        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>精彩活动管理</h1>
                    </div>
                </div>
            </div>
        </section>



        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <button class="btn btn-default" data-toggle="modal" data-target="#myModal">添加精彩活动</button>
                            <form class="form-inline ml-3 pull-right" action="{:url('index')}" method="post">
                                <div class="input-group input-group-sm">
                                    <input class="form-control form-control-navbar" type="text" placeholder="Search" name="keyword" aria-label="Search">
                                    <div class="input-group-append">
                                        <button class="btn btn-default" type="submit">
                                            <i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="card-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th> 序号</th>
                                    <th> 活动名称</th>
                                    <th> 图片</th>
                                    <th> 活动时间</th>
                                    <th> 简介</th>
                                    <th> 价格</th>
                                    <th> 地址</th>
                                    <th> 经纬度</th>
                                    <th> 是否为推荐</th>
                                    <th> 报名人数</th>
                                    <th> 操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name='list' id='vo'}
                                <tr>
                                    <td> {$vo.aid}</td>
                                    <td> {$vo.aname}</td>
                                    <td><img src="__STATIC__/img/{$vo.apic}" style="height: 60px;width: auto;" alt="图片暂无"></td>
                                    <td> {$vo.astarttime}</td>
                                    <td> <pre style="display: -webkit-box;-webkit-line-clamp: 3行数;-webkit-box-orient: vertical;overflow: hidden;">{$vo.aintro}</pre></td>
                                    <td> {$vo.aprice}</td>
                                    <td> {$vo.aaddress}</td>
                                    <td> {$vo.alatitude},{$vo.alongitude}</td>
                                    <td> <?php if($vo['aflag']==1) echo '是'; else echo '否'; ?></td>
                                    <td> {$vo.num} </td>
                                    <td>
                                        <a class="btn btn-default" href="{:url('activities_controller/setFlag',['aid'=>$vo['aid']])}"><?php if($vo['aflag']==1) echo '取消推荐'; else echo '设置推荐'; ?></a>
                                        <button class="btn btn-default" data-aid="{$vo.aid}" onclick="update(this)">修改</button>
                                        <a class="btn btn-default" href="{:url('activities_controller/delete',['aid'=>$vo['aid']])}">删除</a>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                        <!-- /.card-body -->
                        <div class="dataTables_paginate paging_simple_numbers">{$list->render()}</div>
                    </div>
                    <!-- /.card -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->

    </div>
</div>

{include file="public:footfile"}




</body>




<script type="text/javascript">
    function myCheck()
    {
        for(var i=0;i<document.form1.elements.length-1;i++)
        {
            if(document.form1.elements[i].value=="")
            {
                alert("当前表单不能有空项");
                document.form1.elements[i].focus();
                return false;
            }
        }
        return true;

    }
</script>


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">添加精彩活动</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <form role="form" action="{:url('activities_controller/add')}" method="post" enctype="multipart/form-data" name="form1" onsubmit="return myCheck()">
                    <div class="card-body">
                        <div class="form-group">
                            <label>活动名：</label>
                            <input type="text" name="aname" class="form-control" placeholder="请填写活动名称">
                        </div>
                        <div class="form-group">
                            <label>图片：</label>
                            <input type="file" name="apic" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>活动开始时间：</label>
                            <input type="datetime-local" name="astarttime" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>活动简介：</label>
                            <textarea name="aintro" cols="25" rows="3" class="form-control"></textarea>
                        </div>
                        <div class="form-group">
                            <label>费用：</label>
                            <input type="number" name="aprice" class="form-control" placeholder="请填写活动费用">
                        </div>
                        <div class="form-group">
                            <label>地址：</label>
                            <input type="text" name="aaddress" class="form-control" placeholder="请填写活动地址">
                        </div>
                        <div class="form-group">
                            <label>经纬度：</label>
                            <input type="number" step="0.000000001" name="alatitude" class="form-control col-5" placeholder="经度">
                            <input type="number" step="0.000000001" name="alongitude" class="form-control col-5" placeholder="纬度">
                        </div>
                        <input type="hidden" name="aflag" value="0">
                    </div>

            </div>
            <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">提交更改</button>
                </form>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="updateModalLabel">修改精彩活动</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <form role="form" action="{:url('activities_controller/update')}" method="post" enctype="multipart/form-data" name="form1" onsubmit="return myCheck()">
                    <div class="card-body">
                        <div class="form-group">
                            <input type="hidden" id="aid" name="aid">
                            <label>活动名：</label>
                            <input type="text" name="aname" id="aname" class="form-control" placeholder="请填写活动名称">
                        </div>
                        <div class="form-group">
                            <label>图片：</label>
                            <input type="file" name="apic" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>原图片：</label>
                            <img id="yuan_pic" src="__STATIC__/img/logo.jpg" class="form-control" style="height: auto; width: 100px;" alt="">
                        </div>
                        <div class="form-group">
                            <label>活动开始时间：</label>
                            <input type="datetime-local" name="astarttime" id="astarttime" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>活动简介：</label>
                            <textarea name="aintro" cols="25" rows="3" id="aintro" class="form-control"></textarea>
                        </div>
                        <div class="form-group">
                            <label>费用：</label>
                            <input type="number" name="aprice" class="form-control" id="aprice" placeholder="请填写活动费用">
                        </div>
                        <div class="form-group">
                            <label>地址：</label>
                            <input type="text" name="aaddress" class="form-control" id="aaddress" placeholder="请填写活动地址">
                        </div>
                        <div class="form-group">
                            <label>经纬度：</label>
                            <input type="number" name="alatitude" class="form-control col-5" id="alatitude" placeholder="经度">
                            <input type="number" name="alongitude" class="form-control col-5 id="alongitude" placeholder="纬度">
                        </div>
                    </div>

            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">更新</button>
                </form>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>
    function update(that)
    {
        var aid=$(that).attr('data-aid');
        $.ajax({
            url:"{:url('detail_json')}",
            data:{
                id:aid
            },
            dataType:'json',
            success(data){
                var time=data.astarttime;
                $('#aid').val(aid);
                $('#aname').val(data.aname);
                $('#yuan_pic').attr('src','__STATIC__/img/'+data.apic);
                $('#astarttime').val(time);
                $('#aintro').val(data.aintro);
                $('#alatitude').val(data.alatitude);
                $('#alongitude').val(data.alongitude);
                $("#aaddress").val(data.aaddress);
                $('#aprice').val(data.aprice);
                $("#updateModal").modal('show');
            }
        })
    }
</script>

</html>